package com.mobileares.midp.widgets.client.page;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.*;
import com.mobileares.midp.widgets.client.tab.FrameTabItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-4-19
 * Time: 14:02:17
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractPage extends Composite {

    private boolean init = false;
    protected PageClient client;
    private String pageTitle;
    private MenuModel menuModel;
    private PageModel pageModel;
    protected SimplePanel containerWrapper;
    private FrameTabItem.FishTableItemEvent event;

    public FrameTabItem.FishTableItemEvent getEvent() {
        return event;
    }

    public void setEvent(FrameTabItem.FishTableItemEvent event) {
        this.event = event;
    }

    public AbstractPage() {
        containerWrapper = new SimplePanel();
//        DOM.setStyleAttribute(containerWrapper.getElement(), "overflow", "auto");

//        containerWrapper.setSize("100%", "100%");
        initWidget(containerWrapper);
//        setSize("100%","100%");
    }

    public PageModel getPageModel() {
        return pageModel;
    }

    public void setPageModel(PageModel pageModel) {
        this.pageModel = pageModel;
    }

    public SimplePanel getContainer() {
        return containerWrapper;
    }

    public MenuModel getMenuModel() {
        return menuModel;
    }

    public void setWidth(String width) {
        containerWrapper.setWidth(width);
    }

    public void setMenuModel(MenuModel menuModel) {
        this.menuModel = menuModel;
    }

    public void init() {
        if (!init)
            initWidgets();
        init = true;
    }

    public String getPageTitle() {
        return pageTitle;
    }

    public void setPageTitle(String pageTitle) {
        this.pageTitle = pageTitle;
    }

    abstract public void initWidgets();


    public void ddIntModel(Object model) {

    }

    public void reset() {

    }

    public void ddOutModel(Object[] parameters, final Object model) {

        if (isRunAsync() && !init) {
            PageClient client = new PageClient() {
                public void success(AbstractPage page) {
                    ddOutPageModel(model);
                }

                public void failure() {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            };
            AbstractPage.this.client = client;
            init();
        } else {
            init();
            ddOutPageModel(model);
        }
    }

    protected boolean isRunAsync() {
        return false;
    }

    protected abstract void ddOutPageModel(Object dto);

    public AbstractPage getInstance() {
        return null;
    }
}
